﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LX.MVC.Open.CustomExtend
{
    public class CustomHandleErrorAttribute: HandleErrorAttribute
    {
        /// <summary>
        /// 异常发生时，会进入的方法
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnException(ExceptionContext filterContext)
        {
            if (!filterContext.ExceptionHandled)//检查异常有没有被处理过
            {
                filterContext.Result = new ViewResult()
                {
                    ViewName = "~/Views/Shared/Error.cshtml",
                    ViewData = new ViewDataDictionary<string>(filterContext.Exception.Message)
                };


                filterContext.ExceptionHandled = true;//处理完后设置为true
            }
            
        }

    }

}